<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Auth extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{
		$data['title']='Login';
		$this->load->view('login',$data);
	}
	
	function do_login(){
		$user_id	= $this->input->post("username");
		$passwd 	= sha1($this->input->post("password"));
		$query		= $this->db->query("select * from users LEFT JOIN user_position ON user_position.id=users.pos_id JOIN user_group ON users.group_id = user_group.id  where username='$user_id' and password='$passwd'");
		$count		= $query->num_rows();
		if($count>0){
			$row  = $query->row_array();
            //if($row['pos_id']==$this->config->item('se')):
				//if($row['division_id']<>''):
					//$div = $row['division_id'];
				//else:
					//$this->db->where('username',$row['username']);
					//$this->db->update('users',array('division_id'=>0));
					//$div=0;
				//endif;		
                //$query		= $this->db->query("select * from users where division_id=".$div." AND pos_id=".$this->config->item('ta'));
                //$access		= $query->row_array();
                $this->session->set_userdata('user_ta',$row['username']);
            //endif;
			$auth = array(
							'user_id'	   =>	$row['username'],
                            'user_posName' =>	$row['pos_name'],
							'user_pwd'	   =>	$row['password'],
							'user_group'   =>	$row['group_id'],
                            'user_pos'     =>	$row['pos_id']  
						 ); 
			$this->session->set_userdata($auth);
            //$this->access_auth();
			redirect('dashboard',301);
			
		} else {
			$this->session->set_flashdata('message_error','error');
			redirect($this->input->server('HTTP_REFERER'));
		}
	}
	
	function do_logout(){
		$this->session->sess_destroy();
		redirect('auth',301);
	}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */